<div class="content-wrapper">
    <?php
    $form = $this->form;
    $form->prepare();

    //$form->get('admin_group_id')->setEmptyOption('请选择管理员组');

    $form->get('adminName')->setAttributes([
        'placeholder' => $this->translate('管理员账号')
    ]);
    if(isset($user) && $user->getAdminId()) {
        $form->get('adminName')->setAttributes([
            'disabled' => 'disabled'
        ]);
    }

    $form->get('adminEmail')->setAttributes([
        'placeholder' => $this->translate('电子邮箱')
    ]);
    $form->get('adminPassword')->setAttributes([
        'placeholder' => $this->translate('管理员密码')
    ]);
    $form->get('adminComPassword')->setAttributes([
        'placeholder' => $this->translate('确认密码')
    ]);
    ?>
    <?php echo $this->form()->openTag($form); ?>
    <section class="content-header">
        <?php echo $this->partial('layout/breadcrumb'); ?>

        <h1 class="pull-right">
            <a href="<?php echo $this->url('admin');?>" class="btn btn-default btn-sm"><i class="fa fa-arrow-left"></i> <?php echo $this->translate('返回管理员列表'); ?></a>
            <button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-check"></i> <?php echo $this->translate('保存管理员信息'); ?></button>
            <?php echo (isset($user) ? $this->HelpUrl('adminEdit') : $this->HelpUrl('adminAdd')); ?>
        </h1>
    </section>

    <section class="content">

        <div class="row">
            <div class="col-md-12">
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title"><?php echo ((isset($user) && $user->getAdminId()) ? $this->translate('编辑管理员') : $this->translate('添加管理员')); ?></h3>
                    </div>

                        <div class="box-body">
                            <?php echo $this->formElementErrors($form->get('dberp_csrf'), ['class'=>'error-message']); ?>
                            <div class="form-group">
                                <label class="col-sm-2 control-label"><?php echo $this->translate('管理员组'); ?><span class="must_add_value">*</span></label>
                                <div class="col-sm-3">
                                    <?php echo $this->formElement($form->get('adminGroupId')); ?>
                                    <?php echo $this->formElementErrors($form->get('adminGroupId'), ['class'=>'error-message']); ?>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label"><?php echo $this->translate('管理员账号'); ?><span class="must_add_value">*</span></label>
                                <div class="col-sm-6">
                                    <?php echo $this->formElement($form->get('adminName')); ?>
                                    <?php echo $this->formElementErrors($form->get('adminName'), ['class'=>'error-message']); ?>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label"><?php echo $this->translate('电子邮箱'); ?><span class="must_add_value">*</span></label>
                                <div class="col-sm-6">
                                    <?php echo $this->formElement($form->get('adminEmail')); ?>
                                    <?php echo $this->formElementErrors($form->get('adminEmail'), ['class'=>'error-message']); ?>
                                </div>
                            </div>

                            <?php if(!isset($user)) { ?>
                            <div class="form-group">
                                <label class="col-sm-2 control-label"><?php echo $this->translate('管理员密码'); ?><span class="must_add_value">*</span></label>
                                <div class="col-sm-6">
                                    <?php echo $this->formElement($form->get('adminPassword')); ?>
                                    <?php echo $this->formElementErrors($form->get('adminPassword'), ['class'=>'error-message']); ?>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label"><?php echo $this->translate('确认密码'); ?><span class="must_add_value">*</span></label>
                                <div class="col-sm-6">
                                    <?php echo $this->formElement($form->get('adminComPassword')); ?>
                                    <?php echo $this->formElementErrors($form->get('adminComPassword'), ['class'=>'error-message']); ?>
                                </div>
                            </div>
                            <?php } ?>
                            <?php if(!isset($this->user) || (isset($this->user) and $this->user->getAdminId() != 1)) { ?>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><?php echo $this->translate('状态'); ?></label>
                                    <div class="col-sm-6">
                                        <div class="checkbox">
                                            <label>
                                                <?php echo $this->formElement($form->get('adminState')); ?> <?php echo $this->translate('启用'); ?>
                                                <?php echo $this->formElementErrors($form->get('adminState'), ['class'=>'error-message']); ?>
                                            </label>
                                        </div>
                                    </div>
                                </div>
                            <?php } ?>
                        </div>

                        <div>
                            <div class="box-footer">
                                <?php echo $this->formElement($form->get('dberp_csrf')); ?>
                                <button type="submit" class="btn btn-primary col-md-offset-2"><i class="fa fa-check"></i> <?php echo $this->translate('保存管理员信息'); ?></button>
                            </div>
                        </div>

                </div>
            </div>
        </div>

    </section>
    <?php echo $this->form()->closeTag(); ?>
</div>
<script type="text/javascript">
    $(document).ready(function() {
        $("#<?php echo $form->getName(); ?>").validate({
            rules: {
                adminGroupId: {
                    required: true,
                    min:1
                },
                adminEmail: {
                    required: true,
                    email: true
                }
                <?php if(!isset($user)) { ?>
                ,
                adminName: {
                    required: true
                },
                adminPassword: {
                    required: true
                },
                adminComPassword: {
                    required: true,
                    equalTo: "#adminPassword"
                }
                <?php } ?>
            },
            messages: {
                adminGroupId: {
                    required: "<?php echo $this->translate('请选择管理员组'); ?>",
                    min: "<?php echo $this->translate('请选择管理员组'); ?>"
                },
                adminEmail: {
                    required: "<?php echo $this->translate('请输入管理员邮箱'); ?>",
                    email: "<?php echo $this->translate('请输入正确的邮箱地址'); ?>"
                }
                <?php if(!isset($user)) { ?>
                ,
                adminName: {
                    required: "<?php echo $this->translate('请输入管理员账号'); ?>"
                },
                adminPassword: {
                    required: "<?php echo $this->translate('请输入管理员密码'); ?>"
                },
                adminComPassword: {
                    required: "<?php echo $this->translate('请输入确认密码'); ?>",
                    equalTo: "<?php echo $this->translate('两次输入的密码不一致'); ?>"
                }
                <?php } ?>
            }
        });
    });
</script>